package com.myblog.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration //配置类
@EnableSwagger2// 开启Swagger2的自动配置
public class SwaggerConfig {

    @Bean
    public Docket docket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(true)// 关闭下面的扫描配置，默认开启
                .select()
                // any（）：扫描全部
                // none（）：都不扫描
                // basePackage：指定扫描
                // withClassAnnotation扫描类上的注解
                // withMethodAnnotation 扫描方法上的注解
                .apis(RequestHandlerSelectors.basePackage("com.myblog.controller"))// 指定扫描接口目录
//                .paths(PathSelectors.ant("/**"))//筛选请求路径
                .build();
    }

    // 配置swaggerinfo
    private ApiInfo apiInfo(){
        // 作者信息
        Contact contact = new Contact("ming","https://www.baidu.com","791123323@qq.com");
        return new ApiInfo(" 文档",
                "myblog接口文档",
                "1.0",
                "https://www.baidu.com",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }

}
